package com.example.first_examination.Fragment;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.first_examination.Adapter.MyAdapter;
import com.example.first_examination.Base.BaseActivity;
import com.example.first_examination.Bean.DatasBean;
import com.example.first_examination.Bean.JavaBean;
import com.example.first_examination.Presenter.MainPresenter;
import com.example.first_examination.R;
import com.example.first_examination.View.MainView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * A simple {@link Fragment} subclass.
 */
public class MyFragment extends BaseActivity<MainPresenter> implements MainView {


    @BindView(R.id.rlv)
    RecyclerView rlv;
    private ArrayList<DatasBean> list;
    private MyAdapter myAdapter;


    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {
        mPresenter.getData();
    }

    @Override
    protected void initView() {
        list = new ArrayList<>();

        rlv.setLayoutManager(new LinearLayoutManager(getActivity()));
        rlv.addItemDecoration(new DividerItemDecoration(getActivity(),LinearLayoutManager.VERTICAL));
        myAdapter = new MyAdapter(getActivity(), list);
        rlv.setAdapter(myAdapter);
    }

    @Override
    protected void initPresenter() {
        mPresenter = new MainPresenter();
    }

    @Override
    protected int initLayout() {
        return R.layout.fragment_my;
    }

    @Override
    public void setData(JavaBean javaBean) {
        list.addAll(javaBean.getData().getDatas());
        myAdapter.notifyDataSetChanged();
    }

    @Override
    public void showToast(String string) {
        Toast.makeText(getActivity(), string, Toast.LENGTH_SHORT).show();
    }
}
